TWB.New_Module({
	///////////////////////////
	name : "Bots",           //
	author : "enduo",        //
	version : 1.0,           //
	///////////////////////////
	
	settings : {
		auto_skip : {
			type : "checkbox"
		},
	},
	enable_autoskip : true,
	Recruit1 : function(){
		var accept=["barracks","stable","garage"];
		if(TWB.logged(window._content)){
			if(accept.indexOf(TWB.Modules.Icons.Screen())!=-1){
				var inputs=TWB.Xpath("//input[@size='5']",6);
				if(typeof inputs[0]!="undefined"){
					inputs[0].value=inputs[0].nextSibling.nextSibling.textContent.match(/\d+/)[0];
					TWB.Xpath("//input[@type='submit']",9).click();
				}
			}
		}
	},
	Recruit2 : function(){
		var accept=["barracks","stable","garage"];
		if(TWB.logged(window._content)){
			if(accept.indexOf(TWB.Modules.Icons.Screen())!=-1){
				var inputs=TWB.Xpath("//input[@size='5']",6);
				if(typeof inputs[1]!="undefined"){
					inputs[1].value=inputs[1].nextSibling.nextSibling.textContent.match(/\d+/)[0];
					TWB.Xpath("//input[@type='submit']",9).click();
				}
			}
		}
	},
	Recruit3 : function(){
		var accept=["barracks","stable","garage"];
		if(TWB.logged(window._content)){
			if(accept.indexOf(TWB.Modules.Icons.Screen())!=-1){
				var inputs=TWB.Xpath("//input[@size='5']",6);
				if(typeof inputs[2]!="undefined"){
					inputs[2].value=inputs[2].nextSibling.nextSibling.textContent.match(/\d+/)[0];
					TWB.Xpath("//input[@type='submit']",9).click();
				}
			}
		}
	},
	Recruit4 : function(){
		var accept=["barracks","stable","garage"];
		if(TWB.logged(window._content)){
			if(accept.indexOf(TWB.Modules.Icons.Screen())!=-1){
				var inputs=TWB.Xpath("//input[@size='5']",6);
				if(typeof inputs[3]!="undefined"){
					inputs[3].value=inputs[3].nextSibling.nextSibling.textContent.match(/\d+/)[0];
					TWB.Xpath("//input[@type='submit']",9).click();
				}
			}
		}
	},
	// Auto Skip Confirmation Dialogs
	ConfSkip : function(){
		if(TWB.logged()){
			if(TWB.Modules.Bots.enable_autoskip && TWB.get_var("auto_skip",false)){
				if(TWB.URL().match("try=confirm") && TWB.Xpath("//*[@class='attack']",9)===null && TWB.Xpath("//*[@id='inputx']",9)===null){
					setTimeout(function(){
						elo=TWB.Xpath("//*[@type='submit']",9);
						if(elo){
							elo.click();
						}
					},50);
				}
			}
		}
	},
	ToggleConfSkip : function(){
		window.setTimeout(function(){
			TWB.set_var("auto_skip",!TWB.get_var("auto_skip",false));
			TWB.gei("TWB-ConfSkip").setAttribute("checked",TWB.get_var("auto_skip"));
		},250);
	},
	// Ad Blocker
	AdBlock : function(){
		if(TWB.logged()){
			try{
				AD=TWB.Xpath("//*[@id='SkyScraperAd']",9);
				if(typeof AD!="undefined"){
					AD.parentNode.removeChild(AD);
				}
			}catch(e){}
		}
	},
	priority : 100,
	init : function(){
		TWB.Processor.start("auto_skip","Modules.Bots.ConfSkip","*",false);
		TWB.Processor.start("ad_block","Modules.Bots.AdBlock","*",false);
		// Init auto skip button
		if(TWB.gei("TWB-ConfSkip")!=null){
			TWB.gei("TWB-ConfSkip").setAttribute("checked",TWB.get_var("auto_skip"));
			TWB.gei("TWB-ConfSkip").addEventListener("click",TWB.Modules.Bots.ToggleConfSkip,false);
		}
	}
});
